package com.antu.first.service.impl;

import com.antu.first.bean.Reply;
import com.antu.first.dao.ReplyDao;
import com.antu.first.dto.ReplyOperationExecution;
import com.antu.first.enums.ReplyStateEnum;
import com.antu.first.exceptions.ReplyOperationException;
import com.antu.first.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2018/3/6.
 */
@Service
public class ReplyServiceImpl implements ReplyService {

    @Autowired
    private ReplyDao replyDao;

    @Override
    public ReplyOperationExecution insertReply(Reply reply) {
        try {
            int effectNum = replyDao.insertReply(reply);
            if(effectNum != 1){
                return new ReplyOperationExecution(ReplyStateEnum.ERROR);
            }
            return new ReplyOperationExecution(ReplyStateEnum.SUCCESS, reply);
        } catch (Exception e) {
            throw new ReplyOperationException("在插入评论回复的过程中出现错误，错误信息："+e.getMessage());
        }
    }
}
